﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorkStation.Frameworks.EasyBus.Attributes
{
    /// <summary>
    /// 类型扩展方法
    /// </summary>
    public static class TypeExtensions
    {
        /// <summary>
        /// 获取发布标记
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static PublishAttribute GetPublishAttribute(this Type type) 
        {
            return type.GetCustomAttributes(typeof(PublishAttribute), false).FirstOrDefault() as PublishAttribute;
        }

        /// <summary>
        /// 获取订阅标记
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static SubscribeAttribute[] GetSubscribeAttribute(this Type type) 
        {
            return type.GetCustomAttributes(typeof(SubscribeAttribute), false).Cast<SubscribeAttribute>().ToArray();
        }

        /// <summary>
        /// 获取监听标记
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static ListenerAttribute[] GetListenerAttribute(this Type type) 
        {
            return type.GetCustomAttributes(typeof(ListenerAttribute), false).Cast<ListenerAttribute>().ToArray();
        }
    }
}
